/*
 * @Autor: dingxiaolin
 * @Date: 2021-06-02 16:44:56
 * @LastEditors: dingxiaolin
 * @LastEditTime: 2021-06-10 13:46:32
 */
import { onMounted, onUnmounted, computed, unref, ref } from 'vue'
import { deviceEnquire, DEVICE_TYPE } from '@/utils/device'
import { useStore } from '@/store'

export function globalSetting() {
    const store = useStore()
    const theme = computed(() => store.state.app.theme)
    // const layoutMode = computed(() => store.state.app.layout)
    // const fixedHeader = computed(() => store.state.app.fixedHeader)
    // const fixSiderbar = computed(() => store.state.app.fixSiderbar)
    // const fixSidebar = computed(() => store.state.app.fixSiderbar)
    // const contentWidth = computed(() => store.state.app.contentWidth)
    // const autoHideHeader = computed(() => store.state.app.autoHideHeader)
    // const sidebarOpened = computed(() => store.state.app.sidebar)
    // const multiTab = computed(() => store.state.app.multiTab)
    // function isTopMenu() {
    //     return unref(layoutMode) === 'topmenu'
    // }
    // function isSideMenu() {
    //     return !isTopMenu()
    // }
    onMounted(() => {
        // isTopMenu();
        // isSideMenu();
    })

    // return { layoutMode, fixedHeader, fixSiderbar, fixSidebar, contentWidth, autoHideHeader, sidebarOpened, multiTab }
    return { theme }
}
export function mixinDevice() {
    const store = useStore()
    const device = ref('')
    function isMobile() {
        return device.value === DEVICE_TYPE.MOBILE
    }
    function isDesktop() {
        return device.value === DEVICE_TYPE.DESKTOP
    }
    function isTablet() {
        return device.value === DEVICE_TYPE.TABLET
    }
    onMounted(() => {
        deviceEnquire(deviceType => {
            device.value = deviceType;
            switch (deviceType) {
                case DEVICE_TYPE.DESKTOP:
                    // store.commit('app/TOGGLE_DEVICE', 'desktop')
                    // store.dispatch('app/setSidebar', true)
                    break
                case DEVICE_TYPE.TABLET:
                    // store.commit('app/TOGGLE_DEVICE', 'tablet')
                    // store.dispatch('app/setSidebar', false)
                    break
                case DEVICE_TYPE.MOBILE:
                default:
                    // store.commit('app/TOGGLE_DEVICE', 'mobile')
                    // store.dispatch('app/setSidebar', true)
                    break
            }
        })
    })
    return { device }
}
